package com.example.demo.bean.queue.disruptor;

import com.lmax.disruptor.EventHandler;
import com.lmax.disruptor.WorkHandler;

/**
 * 消费者
 * EventHandler用于EventHandlerGroup，WorkHandler用于WorkPool。同时实现两接口，该类对象可同时用于EventHandlerGroup和WorkPool
 */
public class OutputConsumer implements EventHandler<OutputEvent>, WorkHandler<OutputEvent> {
    private String consumerId;
    public OutputConsumer(String consumerId){
        this.consumerId = consumerId;
    }

    /**
     * EventHandler的方法
     * @param output
     * @param sequence
     * @param endOfBatch
     * @throws Exception
     */
    @Override
    public void onEvent(OutputEvent output, long sequence, boolean endOfBatch) throws Exception {
        System.out.println("OutputHandler1 " + this.consumerId + "，消费信息：" + output.getId());
    }

    /**
     * WorkHandler的方法
     * @param output
     * @throws Exception
     */
    @Override
    public void onEvent(OutputEvent output) throws Exception {
        System.out.println("OutputHandler1 " + this.consumerId + "，消费信息：" + output.getId());
    }
}
